﻿using Server.Packets;
using System;
using System.Diagnostics.Contracts;

namespace Server.EventHandlers
{
    /// <summary>
    /// Provides data for a packet related event.
    /// </summary>
    public sealed class PacketEventArgs : EventArgs
    {
        #region Fields

        /// <summary>
        /// The <see cref="T:Server.Packets.Packet" /> related with the event.
        /// </summary>
        private readonly Packet m_packet;

        #endregion

        #region Properties

        /// <summary>
        /// Gets the <see cref="T:Server.Packets.Packet" /> related with the event.
        /// </summary>
        public Packet Packet
        {
            get
            {
                Contract.Ensures(Contract.Result<Packet>() != null);

                return m_packet;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="T:Server.EventHandlers.PacketEventArgs" /> class.
        /// </summary>
        /// <param name="packet">The <see cref="T:Server.Packets.Packet" /> related with the event.</param>
        public PacketEventArgs(Packet packet)
        {
            Contract.Requires<ArgumentNullException>(packet != null);

            m_packet = packet;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Define the invariant valid state for this class.
        /// </summary>
        [ContractInvariantMethod]
        private void InvariantValidState()
        {
            Contract.Invariant(m_packet != null);
        }

        #endregion
    }
}
